package de.akad.imp03.client.ui;

import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.VerticalPanel;

import de.akad.imp03.client.data.Rundendaten;

public class ControlCenter {
	final Rundendaten rd = new Rundendaten();
	final DockPanel mainPanel = new DockPanel();
	final Header header = new Header();
	final Footer footer = new Footer();
	final Navigator nav = new Navigator();
	final Content content = new Content();
	
	public class Header {
		final Grid panel = new Grid(3,1);
		final Grid labelPanel = new Grid(1,3);
		final Label title = new Label("Personalrecruiting mit Web 2.0");
		final Label subtitle = new Label(" ");
		final Label name = new Label("Mr. X");
		final Label budget = new Label("1.000 EUR");
		final Label time = new Label("00:08");

		public Panel onInitialize() {
			panel.addStyleName("cc-header");
			title.addStyleName("header-Label");
			subtitle.addStyleName("header-Label");
			name.addStyleName("header-Label");
			budget.addStyleName("header-Label");
			time.addStyleName("header-Label");
			panel.setWidget(0, 0, title);
			panel.setWidget(1, 0, subtitle);
			panel.setWidget(2, 0, labelPanel);
			
			labelPanel.setWidget(0, 0, name);
			labelPanel.setWidget(0, 1, budget);
			labelPanel.setWidget(0, 2, time);
			
			return panel;
		}
	}
	public class Navigator {
		final Panel panel = new VerticalPanel();
		final Label title = new Label("Steuerzentrale");
		final VerticalPanel menuPanel = new VerticalPanel();
		final VerticalPanel itemPanel = new VerticalPanel();
		final Label ausschreibungen = new Label("Stellenausschreibungen");
		final Label benachrichtigungen = new Label("Benachrichtigungen");
		final Label profile = new Label("Bewerberprofile");
		final Anchor facebook = new Anchor("facebook (50€)");
		final Anchor website = new Anchor("Website (100€)");
		final Anchor stepstone = new Anchor("Stepstone (250€)");
		final Anchor twitter = new Anchor("Twitter (50€)");
		final Anchor xing = new Anchor("XING (150€)");
		final Anchor headhunter = new Anchor("Headhunter (500€)");
		final CheckBox facebookBox = new CheckBox();
		final CheckBox websiteBox = new CheckBox();
		final CheckBox stepstoneBox = new CheckBox();
		final CheckBox twitterBox = new CheckBox();
		final CheckBox xingBox = new CheckBox();
		final CheckBox headhunterBox = new CheckBox();
		
		public Panel onInitialize() {
			panel.addStyleName("cc-nav");
			title.addStyleName("header-Label");
			ausschreibungen.addStyleName("header-Label");
			benachrichtigungen.addStyleName("header-Label");
			profile.addStyleName("header-Label");
			
			panel.add(title);
			menuPanel.add(ausschreibungen);
			menuPanel.add(benachrichtigungen);
			menuPanel.add(profile);
			
			
			facebook.addClickHandler(new ItemCommand(ControlCenter.this, rd, rd.FACEBOOK));
			website.addClickHandler(new ItemCommand(ControlCenter.this, rd, rd.WEBSITE));
			stepstone.addClickHandler(new ItemCommand(ControlCenter.this, rd, rd.STEPSTONE));
			twitter.addClickHandler(new ItemCommand(ControlCenter.this, rd, rd.TWITTER));
			xing.addClickHandler(new ItemCommand(ControlCenter.this, rd, rd.XING));
			headhunter.addClickHandler(new ItemCommand(ControlCenter.this, rd, rd.HEADHUNTER));
			
			facebookBox.setEnabled(false);
			websiteBox.setEnabled(false);
			stepstoneBox.setEnabled(false);
			twitterBox.setEnabled(false);
			xingBox.setEnabled(false);
			headhunterBox.setEnabled(false);
			facebook.addStyleName("item-Label");
			website.addStyleName("item-Label");
			twitter.addStyleName("item-Label");
			xing.addStyleName("item-Label");
			stepstone.addStyleName("item-Label");
			headhunter.addStyleName("item-Label");
			HorizontalPanel hpanel = new HorizontalPanel();
			hpanel.add(facebookBox);
			hpanel.add(facebook);
			itemPanel.add(hpanel);
			hpanel = new HorizontalPanel();
			hpanel.add(websiteBox);
			hpanel.add(website);
			itemPanel.add(hpanel);
			hpanel = new HorizontalPanel();
			hpanel.add(stepstoneBox);
			hpanel.add(stepstone);
			itemPanel.add(hpanel);
			hpanel = new HorizontalPanel();
			hpanel.add(twitterBox);
			hpanel.add(twitter);
			itemPanel.add(hpanel);
			hpanel = new HorizontalPanel();
			hpanel.add(xingBox);
			hpanel.add(xing);
			itemPanel.add(hpanel);
			hpanel = new HorizontalPanel();
			hpanel.add(headhunterBox);
			hpanel.add(headhunter);
			itemPanel.add(hpanel);
			panel.add(menuPanel);
			panel.add(itemPanel);
			
			return panel;
		}
		
	}
	public class Footer {
		final HorizontalPanel panel = new HorizontalPanel();
		final Button okButton = new Button("Fertig");
		final Button cancelButton = new Button("Abbrechen");
		final HorizontalPanel buttonPanel = new HorizontalPanel();
		final ButtonCommand okCommand = new ButtonCommand(ControlCenter.this, rd, rd.NONE);
		final ButtonCommand cancelCommand = new ButtonCommand(ControlCenter.this, rd, rd.NONE);

		public Panel onInitialize() {
			panel.addStyleName("cc-footer");
			buttonPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
			buttonPanel.add(okButton);
			buttonPanel.add(cancelButton);
			panel.add(buttonPanel);
			okButton.addClickHandler(okCommand);
			cancelButton.addClickHandler(cancelCommand);
		
			return panel;
		}
		
	}
	public class Content {
		final VerticalPanel panel = new VerticalPanel();
		
		public void setPanel(Panel p) {
			panel.clear();
			panel.add(p);
		}
		
		public Panel onInitialize() {
			panel.addStyleName("cc-content");
			EmptyContent ec = new EmptyContent();
			panel.add(ec.onInitialize());
			return panel;
		}
		
	}

	public Panel onInitialize() {
		mainPanel.setWidth("100%");
		mainPanel.setHeight("100%");
		mainPanel.add(nav.onInitialize(), DockPanel.EAST);
		mainPanel.add(content.onInitialize(), DockPanel.CENTER);
		mainPanel.add(header.onInitialize(), DockPanel.NORTH);
		mainPanel.add(footer.onInitialize(), DockPanel.SOUTH);
		
		return mainPanel;
	}
}
